<?php
/**
 * Created by PhpStorm.
 * User: Dream
 * Date: 2018/7/25
 * Time: 20:09
 */

namespace App\Http\Controllers\Admin;


use App\Base\BaseFunc;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class XinController extends Controller
{
    public function searchBGStory()
    {
        $data['bgStoryData'] = DB::table('bg_story')
            ->orderby('bg_story_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchBGStory']);
        return view('/admin.xin.searchBGStory',$data);
    }

    public function addBGStory(BaseFunc $baseFunc)
    {
        $input = Input::only('bg_story_name','bg_story_info','bg_story_floor');
        $input['bg_story_time'] = date('Y-m-d H:i:s');
        DB::table('bg_story')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加背景故事成功！",NULL,"/searchBGStory");
    }

    public function bgStoryInfo($id)
    {
        $data['bgStoryData'] = DB::table('bg_story')
            ->where('bg_story_id',$id)
            ->first();
        return view('/admin.xin.bgStoryInfo',$data);
    }

    public function delBGStory(BaseFunc $baseFunc)
    {
        $input = Input::only('bg_story_id');
        $data = DB::table('bg_story')
            ->where('bg_story_id','=',$input['bg_story_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchBGStory');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchBGStory');
        }
    }

    public function searchBaseDo()
    {
        $data['baseDoData'] = DB::table('base_do')
            ->orderby('base_do_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchBaseDo']);
        return view('/admin.xin.searchBaseDo',$data);
    }

    public function addBaseDo(BaseFunc $baseFunc)
    {
        $input = Input::only('base_do_name','base_do_info','base_do_floor');
        $input['base_do_time'] = date('Y-m-d H:i:s');
        DB::table('base_do')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加基本操作成功！",NULL,"/searchBaseDo");
    }

    public function baseDoInfo($id)
    {
        $data['baseDoData'] = DB::table('base_do')
            ->where('base_do_id',$id)
            ->first();
        return view('/admin.xin.baseDoInfo',$data);
    }

    public function delBaseDo(BaseFunc $baseFunc)
    {
        $input = Input::only('base_do_id');
        $data = DB::table('base_do')
            ->where('base_do_id','=',$input['base_do_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchBaseDo');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchBaseDo');
        }
    }

    public function searchGameKey()
    {
        $data['gameKeyData'] = DB::table('game_key')
            ->orderby('game_key_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchGameKey']);
        return view('/admin.xin.searchGameKey',$data);
    }

    public function addGameKey(BaseFunc $baseFunc)
    {
        $input = Input::only('game_key_name','game_key_info','game_key_floor');
        $input['game_key_time'] = date('Y-m-d H:i:s');
        DB::table('game_key')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加游戏指令成功！",NULL,"/searchGameKey");
    }

    public function gameKeyInfo($id)
    {
        $data['gameKeyData'] = DB::table('game_key')
            ->where('game_key_id',$id)
            ->first();
        return view('/admin.xin.gameKeyInfo',$data);
    }

    public function delGameKey(BaseFunc $baseFunc)
    {
        $input = Input::only('game_key_id');
        $data = DB::table('game_key')
            ->where('game_key_id','=',$input['game_key_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchGameKey');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchGameKey');
        }
    }

    public function searchNewAsk()
    {
        $data['newAskData'] = DB::table('new_ask')
            ->orderby('new_ask_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchNewAsk']);
        return view('/admin.xin.searchNewAsk',$data);
    }

    public function addNewAsk(BaseFunc $baseFunc)
    {
        $input = Input::only('new_ask_name','new_ask_info','new_ask_floor');
        $input['new_ask_time'] = date('Y-m-d H:i:s');
        DB::table('new_ask')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加新手问答成功！",NULL,"/searchNewAsk");
    }

    public function newAskInfo($id)
    {
        $data['newAskData'] = DB::table('new_ask')
            ->where('new_ask_id',$id)
            ->first();
        return view('/admin.xin.newAskInfo',$data);
    }

    public function delNewAsk(BaseFunc $baseFunc)
    {
        $input = Input::only('new_ask_id');
        $data = DB::table('new_ask')
            ->where('new_ask_id','=',$input['new_ask_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchNewAsk');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchNewAsk');
        }
    }

    public function searchSpeedWarning()
    {
        $data['speedWarningData'] = DB::table('speed_warning')
            ->orderby('speed_warning_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchSpeedWarning']);
        return view('/admin.xin.searchSpeedWarning',$data);
    }

    public function addSpeedWarning(BaseFunc $baseFunc)
    {
        $input = Input::only('speed_warning_name','speed_warning_info','speed_warning_floor');
        $input['speed_warning_time'] = date('Y-m-d H:i:s');
        DB::table('speed_warning')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加快手说明成功！",NULL,"/searchSpeedWarning");
    }

    public function speedWarningInfo($id)
    {
        $data['speedWarningData'] = DB::table('speed_warning')
            ->where('speed_warning_id',$id)
            ->first();
        return view('/admin.xin.speedWarningInfo',$data);
    }

    public function delSpeedWarning(BaseFunc $baseFunc)
    {
        $input = Input::only('speed_warning_id');
        $data = DB::table('speed_warning')
            ->where('speed_warning_id','=',$input['speed_warning_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchSpeedWarning');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchSpeedWarning');
        }
    }
}